<script>
	import store from "@/store/index.js";
	import CommonConfig from "./common/config";
	// import userApi from "@/api/user.js"
	// import authApi from "utils/auth";
	// import PageApi from "@/api/page"
	// 解析链接中的参数
	const getQueryString = function(url, name) {
		console.log("url = " + url)
		console.log("name = " + name)
		var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
		var r = url.substr(1).match(reg)
		if (r != null) {
			console.log("r = " + r)
			console.log("r[2] = " + r[2])
			return r[2]
		}
		return null;
	}
	export default {
		onLaunch: async function(options) {
			// uni.setStorageSync('token', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5ODk4OTA3OTcsImlhdCI6MTY3ODg1MDc5NywiaWQiOiJhNTE4NTg2NC0wMzRkLTRjMGEtYjc0Yy0wNjAyZjRjYmE4MDQiLCJ1c2VyIjp7Im1lbWJlcl9pZCI6ImE1MTg1ODY0LTAzNGQtNGMwYS1iNzRjLTA2MDJmNGNiYTgwNCIsIm1lbWJlcl9ubyI6IjE1NjE1ODk4NzYzMTA0NjM5IiwibWVtYmVyX25hbWUiOiLlvq7kv6HnlKjmiLciLCJuaWNrX25hbWUiOiLlvq7kv6HnlKjmiLciLCJjZWxscGhvbmUiOiIxNTYxNTg5ODc2MyIsIm1lbWJlcl9sdmxfaWQiOiIxIiwidXNlcl9sZXZlbCI6IiIsImJyYW5jaF91dWlkIjoiYjNmZWExN2QtOTQ4My0zN2UzLTcxNzctMzAwMDRlNWRiYzEzIiwiYnJhbmNoX25vIjoiIiwiYnJhbmNoX25hbWUiOiIiLCJ0YWJsZV9ubyI6IiIsInRhYmxlX25hbWUiOiIifX0.X17y6F2DFp9x0YD1JbTYb0tnNtTLAScT482rmgbrm_s');
			if (store.state.systemInfo == null) {
				let sys = uni.getSystemInfoSync();
				let winWidth = sys.windowWidth;
				let winrate = 750 / winWidth;
				store.commit("set", {
					winrate: winrate,
					scrollH: parseInt(sys.windowHeight * winrate),
					systemInfo: sys,
				});
			}
		},
		onLoad(options) {},
		onShow: function(options) {
			console.log("App Show=============");
			//#ifdef MP-ALIPAY
			let qrUrl = decodeURIComponent(options.query && options.query.qrCode ? options.query.qrCode : '')
			//#endif

			//#ifdef MP-WEIXIN
			// options.query = {}
			// options.query.q = "https://np-miniapp-dev.vivicloud.net.cn/table?branch_uuid=5179d6de-c913-e04b-107d-bb9481d813b1"
			let qrUrl = decodeURIComponent(options.query && options.query.q ? options.query.q : '')
			//#endif

			let branch_uuid = getQueryString(qrUrl, 'branch_uuid')
			let table_no = getQueryString(qrUrl, 'table_no')
			if (branch_uuid) {
        uni.setStorageSync("TABLE_STATUS",true) // 扫码进来首先设置桌号为正常
				uni.setStorageSync("branch_uuid", branch_uuid)
				uni.setStorageSync("table_no", table_no)
				uni.setStorageSync("showQueuing", false)
				store.commit("order/setTableNo", table_no)
				store.commit("order/setBranchUuid", branch_uuid)
				store.commit("page/setShowQueuing", false)
				return
			}

			if (uni.getStorageSync("branch_uuid")) {
				store.commit("order/setTableNo", uni.getStorageSync("table_no"))
				store.commit("order/setBranchUuid", uni.getStorageSync("branch_uuid"))
				store.commit("page/setShowQueuing", false)
				return;
			}

			// 默认值
			store.commit("page/setShowQueuing", true)
			store.commit("order/setBranchUuid", CommonConfig.branch_uuid)
			store.commit("order/setTableNo", CommonConfig.table_no)

			// uni.setStorageSync('options', JSON.stringify(options));
			// uni.setStorageSync("branch_uuid", CommonConfig.branch_uuid)
			// uni.setStorageSync("table_no", CommonConfig.table_no)

			// if(options.query.table_no){
			//   table_no = options.query.table_no
			// }
			// if(options.query.branch_uuid){
			//   branch_uuid = options.query.branch_uuid
			// }

		},
		onHide: function() {
			console.log("App Hide=============");
		},

	};
</script>

<style>
	/*每个页面公共css */
</style>
